package net.xiduth.net.decoders.handlers;

import net.xiduth.Settings;
import net.xiduth.game.Animation;
import net.xiduth.game.ForceTalk;
import net.xiduth.game.World;
import net.xiduth.game.WorldTile;
import net.xiduth.game.npc.NPC;
import net.xiduth.game.npc.familiar.Familiar;
import net.xiduth.game.npc.others.FireSpirit;
import net.xiduth.game.npc.others.LivingRock;
import net.xiduth.game.npc.pet.Pet;
import net.xiduth.game.npc.slayer.Strykewyrm;
import net.xiduth.game.player.CoordsEvent;
import net.xiduth.game.player.Player;
import net.xiduth.game.player.Skills;
import net.xiduth.game.player.actions.Fishing;
import net.xiduth.game.player.actions.Fishing.FishingSpots;
import net.xiduth.game.player.actions.mining.LivingMineralMining;
import net.xiduth.game.player.actions.mining.MiningBase;
import net.xiduth.game.player.actions.runecrafting.SiphonActionCreatures;
import net.xiduth.game.player.actions.thieving.PickPocketAction;
import net.xiduth.game.player.actions.thieving.PickPocketableNPC;
import net.xiduth.game.player.content.PlayerLook;
import net.xiduth.game.player.content.SlayerTask;
import net.xiduth.game.player.content.agility.AgilityPoints;
import net.xiduth.game.player.dialogues.FremennikShipmaster;
import net.xiduth.io.InputStream;
import net.xiduth.utils.Logger;
import net.xiduth.utils.ShopsHandler;
import net.xiduth.utils.npc.NPCSpawns;

public class NPCHandler {

	public static void handleExamine(final Player player, InputStream stream) {
		int npcIndex = stream.readUnsignedShort128();
		boolean forceRun = stream.read128Byte() == 1;
		if (forceRun)
			player.setRun(forceRun);
		final NPC npc = World.getNPCs().get(npcIndex);
		if (npc == null || npc.hasFinished()
				|| !player.getMapRegionsIds().contains(npc.getRegionId()))
			return;
		if (player.getRights() > 1) {
			player.getPackets().sendGameMessage(
					"NPC - [id=" + npc.getId() + ", loc=[" + npc.getX() + ", "
							+ npc.getY() + ", " + npc.getPlane() + "]].");
		}
		player.getPackets().sendNPCMessage(0, npc,
				"It's a " + npc.getDefinitions().name + ".");
		if (player.isSpawnsMode()) {
			try {
				if (NPCSpawns.removeSpawn(npc)) {
					player.getPackets().sendGameMessage("Removed spawn!");
					return;
				}
			} catch (Throwable e) {
				e.printStackTrace();
			}
			player.getPackets().sendGameMessage("Failed removing spawn!");
		}
		if (Settings.DEBUG)
			Logger.log("NPCHandler",
					"examined npc: " + npcIndex + ", " + npc.getId());
	}

	public static void handleOption1(final Player player, InputStream stream) {
		int npcIndex = stream.readUnsignedShort128();
		boolean forceRun = stream.read128Byte() == 1;
		final NPC npc = World.getNPCs().get(npcIndex);
		if (npc == null || npc.isCantInteract() || npc.isDead()
				|| npc.hasFinished()
				|| !player.getMapRegionsIds().contains(npc.getRegionId()))
			return;
		player.stopAll(false);
		if (forceRun)
			player.setRun(forceRun);
		if (npc.getDefinitions().name.contains("Banker")
				|| npc.getDefinitions().name.contains("banker")) {
			player.faceEntity(npc);
			if (!player.withinDistance(npc, 2))
				return;
			npc.faceEntity(player);
			player.getDialogueManager().startDialogue("Banker", npc.getId());
			return;
		}

		if (SiphonActionCreatures.siphon(player, npc))
			return;

		player.setCoordsEvent(new CoordsEvent(npc, new Runnable() {
			@Override
			public void run() {
				npc.resetWalkSteps();
				player.faceEntity(npc);

				if (npc.getId() == 6601) {
					return;
				}

				if (!player.getControlerManager().processNPCClick1(npc))
					return;
				FishingSpots spot = FishingSpots.forId(npc.getId() | 1 << 24);
				if (spot != null) {
					player.getActionManager().setAction(new Fishing(spot, npc));
					return; // its a spot, they wont face us
				} else if (npc.getId() >= 8837 && npc.getId() <= 8839) {
					player.getActionManager().setAction(
							new LivingMineralMining((LivingRock) npc));
					return;
				}
				npc.faceEntity(player);
				if (npc.getId() == 3709) {
					player.getDialogueManager().startDialogue("MrEx",
							npc.getId());
				}
				if (npc.getId() == 519) {
					player.getDialogueManager().startDialogue("LostBob", 
							519);
				}
				/**
				 * 
				 * Magic instructor
				 * 
				 */
				else if (npc.getId() == 4707) {
				player.getDialogueManager().startDialogue("SimpleMessage", "The instructor hands you some runes.");
				player.getInventory().addItem(556, 5);
				player.getInventory().addItem(558, 5);
				}
				/**
				 * 
				 * Ranged instructor
				 * 
				 */
				else if (npc.getId() == 1861) {
				player.getDialogueManager().startDialogue("SimpleMessage", "The instructor hands you a bow and some arrows.");
				player.getInventory().addItem(841, 1);
				player.getInventory().addItem(882, 50);
				}
				/**
				 * 
				 * Melee instructor
				 * 
				 */
				else if (npc.getId() == 705) {
					player.getDialogueManager().startDialogue("SimpleMessage", "The instructor hands you a sword and shield.");
					player.getInventory().addItem(9703, 1);
					player.getInventory().addItem(9704, 1);
				}
				/**
				 * 
				 * Guards to Al-kraid
				 * 
				 */
				else if (npc.getId() == 2998) {
					player.getDialogueManager().startDialogue("GambleItemD", 2998, 0);
				}
				else if (npc.getId() == 5566) {
					//player.getInterfaceManager().sendLucienOptions();
					player.getDialogueManager().startDialogue(
							"Khazard", 5566);
				}
				else if (npc.getId() == 925) 
					player.setNextWorldTile(new WorldTile (3268, 3227, 0));
				else if (npc.getId() == 926) 
					player.setNextWorldTile(new WorldTile (3267, 3227, 0));
			/**
			 * 
			 * Smuggler for leaving instance.
			 * 
			 */
				/*else if (npc.getId() == 11226) {
					player.getControlerManager().forceStop();
					player.lock(10); 
					player.getControlerManager().removeControlerWithoutCheck();
					player.lock(10); 
					for (Item item : player.getInventory().getItems().toArray()) {
						if (item == null) continue;
						player.getInventory().deleteItem(item);
					}
					for (Item item : player.getEquipment().getItems().toArray()) {
						if (item == null) continue;
						player.getEquipment().deleteItem(item.getId(), item.getAmount());
					}
					if (player.getFamiliar() != null) {
						if (player.getFamiliar().getBob() != null)
							player.getFamiliar().getBob().getBeastItems().clear();
						player.getFamiliar().dissmissFamiliar(false);
					}
					player.getPackets().closeInterface(player.getInterfaceManager().hasRezizableScreen() ? 746 : 548, player.getInterfaceManager().hasRezizableScreen() ? 11: 27);
				} */ //backup
				
				else if (npc.getId() == 11226) {
					player.getDialogueManager().startDialogue("DungLeaving");
					player.lock(3);
				}
				else if (npc.getId() == 5532)
					player.getDialogueManager().startDialogue(
							"SorceressGardenNPCs", npc);
				else if (npc.getId() == 5563)
					player.getDialogueManager().startDialogue(
							"SorceressGardenNPCs", npc);
				else if (npc.getId() == 5559)
					player.sendDeath(npc);
				/**
				 * 
				 * Artefacts.
				 * 
				 */
				/*else if (npc.getId() == 6537)
					player.getDialogueManager().startDialogue("ArtefactExchange",
							npc.getId()); */
				else if (npc.getId() == 1917)
					player.getDialogueManager().startDialogue("Player_Shop_Manager", npc.getId());
				else if (npc.getId() == 1063)
					player.getDialogueManager().startDialogue("PvMRewards",
							npc.getId());
				else if (npc.getId() == 7411)
					player.getDialogueManager().startDialogue("SkillsRewards",
							npc.getId());
				else if (npc.getId() == 15558)
					player.getDialogueManager().startDialogue("RankShop",
							npc.getId());
				else if (npc.getId() == 1064)
					player.getDialogueManager().startDialogue("Page2PvM",
							npc.getId());
				else if (npc.getId() == 8031)
					player.getDialogueManager().startDialogue("Acanatha",
							npc.getId());
				else if (npc.getId() == 591) {
					player.getDialogueManager().startDialogue("LostBob", 591);
				}
				else if (npc.getId() == 7753)  {
					player.getInterfaceManager().sendXMI();
					npc.getId();
				}
				else if (npc.getId() == 15451 && npc instanceof FireSpirit) {
					FireSpirit spirit = (FireSpirit) npc;
					spirit.giveReward(player);
				} else if (npc.getId() == 949)
					player.getDialogueManager().startDialogue("QuestGuide",
							npc.getId(), null);
				else if (npc.getId() == 7412)
					player.getDialogueManager().startDialogue("TriviaRewards");
				else if (npc.getId() == 3373)
					player.getDialogueManager().startDialogue("Max",
							npc.getId(), null);
				else if (npc.getId() >= 1 && npc.getId() <= 6
						|| npc.getId() >= 7875 && npc.getId() <= 7884)
					player.getDialogueManager().startDialogue("Man",
							npc.getId());
				else if (npc.getId() == 198)
					player.getDialogueManager().startDialogue("Guildmaster",
							npc.getId());
				else if (npc.getId() == 13934) 
					player.getDialogueManager().startDialogue("DonatorShops");			
				else if (npc.getId() == 9741)
					player.getDialogueManager().startDialogue("SimpleNPCMessage", 9741, "Welcome to Daemonheim.");
				else if (npc.getId() == 8339)
					player.getDialogueManager().startDialogue("SimpleNPCMessage", 8339, "Fuck off...");
				else if (npc.getId() == 918)
					player.getDialogueManager().startDialogue("SimpleNPCMessage", 918, "Howdy.");
				else if (npc.getId() == 2634)
					player.getDialogueManager().startDialogue("SimpleNPCMessage", 2634, "Hey, how are you " + player.getDisplayName() + " ?");
				else if (npc.getId() == 9462)
					Strykewyrm.handleStomping(player, npc);
				else if (npc.getId() == 9464)
					Strykewyrm.handleStomping(player, npc);
				else if (npc.getId() == 9466)
					Strykewyrm.handleStomping(player, npc);		
				else if (npc.getId() == 9707)
					player.getDialogueManager().startDialogue(
							"FremennikShipmaster", npc.getId(), true);
				else if (npc.getId() == 9708)
					player.getDialogueManager().startDialogue(
							"FremennikShipmaster", npc.getId(), false);
				else if (npc.getId() == 4874)
					player.getDialogueManager().startDialogue(
							"VoteRewards", npc.getId(), false);
				else if (npc.getId() == 2992)
					player.getDialogueManager().startDialogue(
							"FrostRewards", npc.getId(), false);
				else if (npc.getId() == 8726)
					AgilityPoints.sendExchange(player);
				/**
				 * 
				 * Sheepies :3
				 * 
				 */
				else if (npc.getId() == 8876) {
					player.setNextAnimation(new Animation(893)); 
					player.lock(5);
					player.getInventory().addItem(1737, 1);
					player.getPackets().sendGameMessage("You shear the sheep and get some wool.");
					player.getSkills().addXp(Skills.CRAFTING, 3);
				}
				else if (npc.getId() == 5160) {
					player.setNextAnimation(new Animation(893)); 
					player.lock(5);
					player.getInventory().addItem(1737, 1);
					player.getPackets().sendGameMessage("You shear the sheep and get some wool.");
					player.getSkills().addXp(Skills.CRAFTING, 3);
				}
				else if (npc.getId() == 5156) {
					player.setNextAnimation(new Animation(893)); 
					player.lock(5);
					player.getInventory().addItem(1737, 1);
					player.getPackets().sendGameMessage("You shear the sheep and get some wool.");
					player.getSkills().addXp(Skills.CRAFTING, 3);
				}
				else if (npc.getId() == 43) {
					player.setNextAnimation(new Animation(893)); 
					player.lock(5);
					player.getInventory().addItem(1737, 1);
					player.getPackets().sendGameMessage("You shear the sheep and get some wool.");
					player.getSkills().addXp(Skills.CRAFTING, 3);
				}
				else if (npc.getId() == 1765) {
					player.setNextAnimation(new Animation(893)); 
					player.lock(5);
					player.getInventory().addItem(1737, 1);
					player.getPackets().sendGameMessage("You shear the sheep and get some wool.");
					player.getSkills().addXp(Skills.CRAFTING, 3);
				}
				/**
				 * 
				 * End of sheepies.
				 * 
				 */
		/**
		 * 
		 * Start of all Lumbridge NPCs.
		 * 
		 */
				else if (npc.getId() == 945)
					player.getDialogueManager().startDialogue("XiduthGuide");				
				else if (npc.getId() == 3777)
					player.getDialogueManager().startDialogue("SimpleMessage", "The man says nothing and ignores you.");
				else if (npc.getId() == 239)
					  player.getInterfaceManager().sendDungShop();
				else if (npc.getId() == 11270)
					player.getDialogueManager().startDialogue("SimpleNPCMessage", 11270, "Nice try, bud.");
				else if (npc.getId() == 6537) //fixed..
					player.getDialogueManager().startDialogue("DonatorShops");
				else if (npc.getId() == 2676)
					player.getDialogueManager().startDialogue("MakeOverMage",
							npc.getId(), 0);
				else if (npc.getId() == 9085)
					player.getDialogueManager().startDialogue("Kuradal",
							npc.getId(), 0);
				else if (npc.getId() == 13929)
					player.getDialogueManager().startDialogue("Ariane",
							npc.getId());
				else if (npc.getId() == 15417)
					player.getDialogueManager().startDialogue("RuneSpanStore",
							npc.getId());
				else if (npc.getId() == 15419)
					player.getDialogueManager().startDialogue("RuneSpanPortalD",
							npc.getId());
				else if (npc.getId() == 8462)
					player.getDialogueManager().startDialogue("Spria",
							npc.getId(), 0);
				else if (npc.getId() == 895)
					player.getDialogueManager().startDialogue("EstateSeller",
							npc.getId());
				else if (npc.getId() == 15418)
					player.getDialogueManager().startDialogue(
							"RuneSpanLeaving", npc.getId());
				else if (npc.getId() == 8464)
					player.getDialogueManager().startDialogue("Mazchna",
							npc.getId(), 0);
				else if (npc.getId() == 598)
					player.getDialogueManager().startDialogue("Hairdresser",
							npc.getId());
				else if (npc.getId() == 13727) // loyalty shop -dray
					player.getDialogueManager().startDialogue("Xuan",
							npc.getId());
				else if (npc.getId() == 13697)
					player.getDialogueManager().startDialogue("CaptainJute",
							npc.getId());
				else if (npc.getId() == 8091)
					player.getDialogueManager().startDialogue("StarSprite");
				else if (npc.getId() == 548)
					player.getDialogueManager().startDialogue("Thessalia",
							npc.getId());
				else if (npc.getId() == 659)
					player.getDialogueManager().startDialogue("PartyPete");
				else if (npc.getId() == 579)
					player.getDialogueManager().startDialogue("DrogoDwarf",
							npc.getId());
				else if (npc.getId() == 529) // edge
					player.getDialogueManager().startDialogue("GeneralStore",
							npc.getId(), 1);
				else if (npc.getId() == 522 || npc.getId() == 523) // varrock
					player.getDialogueManager().startDialogue("GeneralStore",
							npc.getId(), 1);
				else if (npc.getId() == 521) // lumbridge
					player.getDialogueManager().startDialogue("GeneralStore",
							npc.getId(), 1);
				else if (npc.getId() == 594)
					player.getDialogueManager().startDialogue("Nurmof",
							npc.getId());
				else if (npc.getId() == 587)
					player.getDialogueManager().startDialogue("Jatix",
							npc.getId());
				else if (npc.getId() == 14866)
					player.getDialogueManager().startDialogue("SummoningShop",
							npc.getId());
				else if (npc.getId() == 665)
					player.getDialogueManager().startDialogue("BootDwarf",
							npc.getId());
				else if (npc.getId() == 382 || npc.getId() == 3294
						|| npc.getId() == 4316)
					player.getDialogueManager().startDialogue(
							"MiningGuildDwarf", npc.getId(), false);
				else if (npc.getId() == 3295)
					player.getDialogueManager().startDialogue(
							"MiningGuildDwarf", npc.getId(), true);
				else if (npc.getId() == 537)
					player.getDialogueManager().startDialogue("Scavvo",
							npc.getId());
				/** Skillcapes **/
				else if (npc.getId() == 4288)
					player.getDialogueManager().startDialogue("Ajjat",
							npc.getId());
				else if (npc.getId() == 4297)
					player.getDialogueManager().startDialogue("Sloane",
							npc.getId());
				else if (npc.getId() == 682)
					player.getDialogueManager().startDialogue("ArmourSalesman",
							npc.getId());
				else if (npc.getId() == 802)
					player.getDialogueManager().startDialogue("BrotherJered",
							npc.getId());
				else if (npc.getId() == 1658)
					player.getDialogueManager().startDialogue("RobeStoreOwner",
							npc.getId());
				else if (npc.getId() == 13632)
					player.getDialogueManager().startDialogue("Larriar",
							npc.getId());
				else if (npc.getId() == 961)
					player.getDialogueManager().startDialogue(
							"SurgeonGeneralTafani", npc.getId());
				else if (npc.getId() == 437)
					player.getDialogueManager().startDialogue(
							"CapnIzzyNoBeard", npc.getId());
				else if (npc.getId() == 2270)
					player.getDialogueManager().startDialogue("MartinThwait",
							npc.getId());
				else if (npc.getId() == 805)
					player.getDialogueManager().startDialogue("MasterCrafter",
							npc.getId());
				else if (npc.getId() == 575)
					player.getDialogueManager().startDialogue("Hickton",
							npc.getId());
				else if (npc.getId() == 5113)
					player.getDialogueManager().startDialogue("HuntingExpert",
							npc.getId());
				else if (npc.getId() == 4247)
					player.getDialogueManager().startDialogue("EstateAgent",
							npc.getId());
				/** DWARF **/
				/**
				 * else if (npc.getId() == 575)
				 * player.getDialogueManager().startDialogue("Hickton",
				 * npc.getId());
				 **/
				else if (npc.getId() == 604)
					player.getDialogueManager().startDialogue("Thurgo",
							npc.getId());
				else if (npc.getId() == 308)
					player.getDialogueManager().startDialogue("MasterFisher",
							npc.getId());
				else if (npc.getId() == 847)
					player.getDialogueManager().startDialogue("HeadChef",
							npc.getId());
				else if (npc.getId() == 4946)
					player.getDialogueManager().startDialogue("IgnatiusVulcan",
							npc.getId());
				else if (npc.getId() == 4906)
					player.getDialogueManager().startDialogue("Wilfred",
							npc.getId());
				else if (npc.getId() == 456)
					player.getDialogueManager().startDialogue("ZarosAltar",
							npc.getId());
				else if (npc.getId() == 3299)
					player.getDialogueManager().startDialogue(
							"MartintheMasterGardener", npc.getId());
				else if (npc.getId() == 17)
					player.getDialogueManager().startDialogue(
							"RunespanPortalD", npc.getId(), 0);
				else if (npc.getId() == 9713)
					player.getDialogueManager().startDialogue("Thok",
							npc.getId());
				if (npc.getName().toLowerCase().contains("exchange clerk")) {
					player.getDialogueManager().startDialogue("ExchangeClerk", npc.getId());
					return;
				}
				else if (npc.getId() == 6524)
					player.getDialogueManager().startDialogue("BobBarterD",
							npc.getId());
				/** End of Skillcapes **/
				else if (npc.getId() == 536)
					player.getDialogueManager().startDialogue("Valaine",
							npc.getId());
				else if (npc.getId() == 4563) // Crossbow Shop
					player.getDialogueManager().startDialogue("Hura",
							npc.getId());
				else if (npc.getId() == 2617)
					player.getDialogueManager().startDialogue("TzHaarMejJal",
							npc.getId());
				else if (npc.getId() == 2618)
					player.getDialogueManager().startDialogue("TzHaarMejKah",
							npc.getId());
				else if (npc.getId() == 15149)
					player.getDialogueManager()
							.startDialogue("MasterOfFear", 0);
				else if (npc.getId() == 519)
					player.getDialogueManager().startDialogue("Bob", 0);
				else if (npc.getId() == 0)
					player.getDialogueManager().startDialogue(
							"SkillingTeleports", 0);
				else if (npc.getId() == 7935)
					player.getDialogueManager().startDialogue("Hans", 0);
				else if (npc.getId() == 278)
					  player.getDialogueManager().startDialogue("CooksAssistant", npc.getId());
				else if (npc.getId() == 758)
					  player.getDialogueManager().startDialogue("Fred", npc.getId());
				else if (npc.getId() == 3807)
					  player.getDialogueManager().startDialogue("Groats", npc.getId());
				else if (npc.getId() == 7888 && (player.hasDoneCook()))
					  player.getDialogueManager().startDialogue("SkillsInstructor", npc.getId());
				else if (npc.getId() == 6539 && (player.hasDoneSkillsTutorial()))
					  player.getDialogueManager().startDialogue("Nasaroth", npc.getId());
				
				/**
				 * Shops
				 */

				else if (npc.getId() == 3205)
					ShopsHandler.openShop(player, 51);				
				else if (npc.getId() == 549)
					ShopsHandler.openShop(player, 3);
				else if (npc.getId() == 5112)
					ShopsHandler.openShop(player, 29);
				else if (npc.getId() == 683)
					ShopsHandler.openShop(player, 4);
				else if (npc.getId() == 552)
					ShopsHandler.openShop(player, 7);
				else if (npc.getId() == 455)
					player.getDialogueManager().startDialogue("KaqemeexShop",
							npc.getId());
				else if (npc.getId() == 6988)
					ShopsHandler.openShop(player, 8);
				else if (npc.getId() == 546)
					ShopsHandler.openShop(player, 11);
				else if (npc.getId() == 528)
					ShopsHandler.openShop(player, 9);
				else if (npc.getId() == 520)
					ShopsHandler.openShop(player, 10);
				else if (npc.getId() == 3021) // tool lep for farming -oracle
					ShopsHandler.openShop(player, 18);

				/**
				 * Prestige NPC
				 */

				else if (npc.getId() == 2253) 
					player.getDialogueManager().startDialogue("PrestigeOne");
				else if (npc instanceof Pet) {
					Pet pet = (Pet) npc;
					if (pet != player.getPet()) {
						player.getPackets().sendGameMessage(
								"This isn't your pet.");
						return;
					}
					player.setNextAnimation(new Animation(827));
					pet.pickup();
				} else {
					player.getPackets().sendGameMessage(
							"Nothing interesting happens.");
					if (Settings.DEBUG)
						System.out.println("cliked 1 at npc id : "
								+ npc.getId() + ", " + npc.getX() + ", "
								+ npc.getY() + ", " + npc.getPlane());
				}
			}
		}, npc.getSize()));
	}

	public static void handleOption2(final Player player, InputStream stream) {
		int npcIndex = stream.readUnsignedShort128();
		boolean forceRun = stream.read128Byte() == 1;
		final NPC npc = World.getNPCs().get(npcIndex);
		if (npc == null || npc.isCantInteract() || npc.isDead()
				|| npc.hasFinished()
				|| !player.getMapRegionsIds().contains(npc.getRegionId()))
			return;
		player.stopAll(false);
		if (forceRun)
			player.setRun(forceRun);
		if (npc.getDefinitions().name.contains("Banker")
				|| npc.getDefinitions().name.contains("banker")) {
			player.faceEntity(npc);
			if (!player.withinDistance(npc, 2))
				return;
			npc.faceEntity(player);
			player.getBank().openBank();
			return;
		}
		if (npc.getDefinitions().name.contains("Xuan")) {
				ShopsHandler.openShop(player, 15);
				return;
		}
		if (npc.getId() == 8031) {
			player.getInterfaceManager().sendInvasionShop();
			return;
		}
		else if (npc.getName().toLowerCase().contains("exchange clerk"))  {
			player.getGrandExchange().sendExchangeScreen();
			return;
			}
		
		player.setCoordsEvent(new CoordsEvent(npc, new Runnable() {
			@Override
			public void run() {
				npc.resetWalkSteps();
				player.faceEntity(npc);
				FishingSpots spot = FishingSpots.forId(npc.getId() | (2 << 24));
				if (spot != null) {
					player.getActionManager().setAction(new Fishing(spot, npc));
					return;
				}
				PickPocketableNPC pocket = PickPocketableNPC.get(npc.getId());
				if (pocket != null) {
					player.getActionManager().setAction(
							new PickPocketAction(npc, pocket));
					return;
				}
				if (npc instanceof Familiar) {
					if (npc.getDefinitions().hasOption("store")) {
						if (player.getFamiliar() != npc) {
							player.getPackets().sendGameMessage(
									"That isn't your familiar.");
							return;
						}
						player.getFamiliar().store();
					} else if (npc.getDefinitions().hasOption("cure")) {
						if (player.getFamiliar() != npc) {
							player.getPackets().sendGameMessage(
									"That isn't your familiar.");
							return;
						}
						if (!player.getPoison().isPoisoned()) {
							player.getPackets().sendGameMessage(
									"Your arent poisoned or diseased.");
							return;
						} else {
							player.getFamiliar().drainSpecial(2);
							player.addPoisonImmune(120);
						}
					}
					return;
				}
				npc.faceEntity(player);
				if (!player.getControlerManager().processNPCClick2(npc))
					return;
				if (npc.getId() == 9707)
					FremennikShipmaster.sail(player, true);
				else if (npc.getId() == 9708)
					FremennikShipmaster.sail(player, false);
				else if (npc.getId() == 13455 || npc.getId() == 2617
						|| npc.getId() == 2618 || npc.getId() == 15194)
					player.getBank().openBank();
				else if (npc.getId() == 15149)
					player.getDialogueManager()
							.startDialogue("MasterOfFear", 3);
				else if (npc.getId() == 2676)
					PlayerLook.openMageMakeOver(player);
				else if (npc.getId() == 598)
					PlayerLook.openHairdresserSalon(player);
				else if (npc instanceof Pet) {
					if (npc != player.getPet()) {
						player.getPackets().sendGameMessage(
								"This isn't your pet!");
						return;
					}
					Pet pet = player.getPet();
					player.getPackets().sendMessage(
							99,
							"Pet [id=" + pet.getId() + ", hunger="
									+ pet.getDetails().getHunger()
									+ ", growth="
									+ pet.getDetails().getGrowth() + ", stage="
									+ pet.getDetails().getStage() + "].",
							player);
				} else {
					player.getPackets().sendGameMessage(
							"Nothing interesting happens.");
					if (Settings.DEBUG)
						System.out.println("cliked 2 at npc id : "
								+ npc.getId() + ", " + npc.getX() + ", "
								+ npc.getY() + ", " + npc.getPlane());
				}
			}
		}, npc.getSize()));
	}

	public static void handleOption3(final Player player, InputStream stream) {
		int npcIndex = stream.readUnsignedShort128();
		boolean forceRun = stream.read128Byte() == 1;
		final NPC npc = World.getNPCs().get(npcIndex);
		if (npc == null || npc.isCantInteract() || npc.isDead()
				|| npc.hasFinished()
				|| !player.getMapRegionsIds().contains(npc.getRegionId()))
			return;
		player.stopAll(false);
		if (forceRun)
			player.setRun(forceRun);
		player.setCoordsEvent(new CoordsEvent(npc, new Runnable() {
			@Override
			public void run() {
				npc.resetWalkSteps();
				if (!player.getControlerManager().processNPCClick3(npc))
					return;
				player.faceEntity(npc);
				if (npc.getId() >= 8837 && npc.getId() <= 8839) {
					MiningBase.propect(player, "You examine the remains...",
							"The remains contain traces of living minerals.");
					return;

				}
				npc.faceEntity(player);
				if (npc.getId() == 9085) {
					SlayerTask.sendBuy(player);
				}
				if (npc.getId() == 8462) {
					SlayerTask.sendBuy(player);
				}
				if (npc.getId() == 8464) {
					SlayerTask.sendBuy(player);
				} else if (npc.getId() == 548)
					PlayerLook.openThessaliasMakeOver(player);
				else if (npc.getId() == 5532) {
					npc.setNextForceTalk(new ForceTalk(
							"Senventior Disthinte Molesko!"));
					player.getControlerManager().startControler(
							"SorceressGarden");

				} else
					player.getPackets().sendGameMessage(
							"Nothing interesting happens.");
			}

		}, npc.getSize()));
		if (Settings.DEBUG)
			System.out.println("cliked 3 at npc id : " + npc.getId() + ", "
					+ npc.getX() + ", " + npc.getY() + ", " + npc.getPlane());
	}

	public static void handleOption4(final Player player, InputStream stream) {
		int npcIndex = stream.readUnsignedShort128();
		boolean forceRun = stream.read128Byte() == 1;
		final NPC npc = World.getNPCs().get(npcIndex);
		if (npc == null || npc.isCantInteract() || npc.isDead()
				|| npc.hasFinished()
				|| !player.getMapRegionsIds().contains(npc.getRegionId()))
			return;
		player.stopAll(false);
		if (forceRun)
			player.setRun(forceRun);
		player.setCoordsEvent(new CoordsEvent(npc, new Runnable() {
			@Override
			public void run() {
				npc.resetWalkSteps();
				if (!player.getControlerManager().processNPCClick4(npc))
					return;
				player.faceEntity(npc);
				npc.faceEntity(player);
				if (npc.getId() == 9085) {
					if (player.getSlayerPoints() >= 400) {
						player.getInventory().addItem(22528, 1);
						player.setSlayerPoints(player.getSlayerPoints() - 400);
					} else
						player.sendMessage("You need 400 Slayer Points to purchase the Full Slayer Helmet.");
				}
				if (npc.getId() == 13697) { //troll interface
				player.getInterfaceManager().sendTrollShop();
				}
				if (npc.getId() == 8462) {
					if (player.getSlayerPoints() >= 400) {
						player.getInventory().addItem(22528, 1);
						player.setSlayerPoints(player.getSlayerPoints() - 400);
					} else
						player.sendMessage("You need 400 Slayer Points to purchase the Full Slayer Helmet.");
				} else if (npc.getId() == 5532) {
					npc.setNextForceTalk(new ForceTalk(
							"Senventior Disthinte Molesko!"));
					player.getControlerManager().startControler(
							"SorceressGarden");

				} 
				else
					player.getPackets().sendGameMessage(
							"Nothing interesting happens.");
			}

		}, npc.getSize()));
		if (Settings.DEBUG)
			System.out.println("cliked 4 at npc id : " + npc.getId() + ", "
					+ npc.getX() + ", " + npc.getY() + ", " + npc.getPlane());
	}
}
